package Player;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
/**
 *
 * @author Joakim
 */
public class Player{

    private int health;
    private int xPos;
    private int yPos;

    private boolean left = false;
    private boolean right = false;
    private boolean up = false;
    private boolean down = false;
    private boolean shoot = false;
    private boolean newShot = false;

    int x;
    int y;

    Image playerShip;
    Image projectile;

    Projectile ptile;

    public Player(){
        xPos = 200;
        yPos = 200;
        health = 10;
        //x = ptile.getXPos();
        //y = ptile.getYPos();
    }

    public void setXPos(int xPos){
        this.xPos = this.xPos + xPos;
    }

    public int getXPos(){
        return xPos;
    }

    public void setYPos(int yPos){
        this.yPos = this.yPos + yPos;
    }

    public int getYPos(){
        return yPos;
    }

    public void setHealth(int health){
        this.health = health;
    }

    public void changeHealth(int health){
        this.health = this.health + health;
    }

    public int getHealth(){
        return health;
    }

    public void Draw(Graphics g){

        projectile = new ImageIcon("images/projectile.gif") {}.getImage();
        playerShip = new ImageIcon("images/memeShip.gif") {}.getImage();
        g.drawImage(projectile, xPos+40, yPos+40, 19, 50, null);
        g.drawImage(playerShip, xPos, yPos, 100, 100, null);
    }

    public void checkButtons(int keyCode){
        if(keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_KP_LEFT){
            left = true;
        }
        if(keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_KP_RIGHT){
            right = true;
        }
        if(keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP){
            up = true;
        }
        if(keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN){
            down = true;
        }

        if(keyCode == KeyEvent.VK_SPACE){
            shoot = true;
        }
    }

    public void moveShip(){
        if(left){
            setXPos(-1);
        }
        if(right){
            setXPos(1);
        }
        if(up){
            setYPos(-1);
        }
        if(down){
            setYPos(1);
        }
    }

    public void startShooting(){
        if(shoot && !newShot){
            ptile = new Projectile(xPos, yPos);
            newShot = true;
        }
        if(newShot){
            ptile.moveProjectile();
        }
    }

    public void stopShooting(int keyCode){
        if(keyCode == KeyEvent.VK_SPACE || ptile.checkProjectile()){
            newShot = false;
            shoot = false;
        }
    }
    
    public void stopShip(int keyCode){
        if(keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_KP_LEFT){
            left = false;
        }
        if(keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_KP_RIGHT){
            right = false;
        }
        if(keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_KP_UP){
            up = false;
        }
        if(keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_KP_DOWN){
            down = false;
        }
    }

}
